<template>
  <div>
    <!-- 相关视频推荐 -->
    <div class="recommend">
      <span class="recommend-top">相关推荐</span>
      <div
        class="recommend-list"
        v-for="(item, index) in recommendVideo"
        :key="index"
        @click="$router.push({ name: 'Video', query: { aid: item.aid, bvid: item.bvid } })"
      >
        <div class="recommend-video">
          <img class="video" :src="item.pic" />
        </div>
        <div class="recommend-info">
          <span class="recommend-title">{{ item.title }}</span>
          <div class="recommend-up">{{ item.owner.name }}</div>
          <div class="recommend-number">
            {{ item.stat.view }}万 播放 · {{ item.stat.danmuku }}万 弹幕
          </div>
        </div>
      </div>
      <!-- <div class="recommend-list">
        <div class="recommend-video">
          <video
            class="video"
            src="https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4"
          >
          </video>
        </div>
        <div class="recommend-info">
          <span class="recommend-title"> 【艾叔】上海陆家嘴，中国企业家的豪宅长什么样 </span>
          <div class="recommend-up"> 小艾大叔 </div>
          <div class="recommend-number">768.0万 播放 · 9.6万 弹幕</div>
        </div>
      </div>
      <div class="recommend-list">
        <div class="recommend-video">
          <video
            class="video"
            src="https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4"
          >
          </video>
        </div>
        <div class="recommend-info">
          <span class="recommend-title"> 【艾叔】上海陆家嘴，中国企业家的豪宅长什么样 </span>
          <div class="recommend-up"> 小艾大叔 </div>
          <div class="recommend-number">768.0万 播放 · 9.6万 弹幕</div>
        </div>
      </div>
      <div class="recommend-list">
        <div class="recommend-video">
          <video
            class="video"
            src="https://cdn.jsdelivr.net/gh/xdlumia/files/video-play/IronMan.mp4"
          >
          </video>
        </div>
        <div class="recommend-info">
          <span class="recommend-title"> 【艾叔】上海陆家嘴，中国企业家的豪宅长什么样 </span>
          <div class="recommend-up"> 小艾大叔 </div>
          <div class="recommend-number">768.0万 播放 · 9.6万 弹幕</div>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent, watch } from 'vue'
  import { useRoute } from 'vue-router'
  export default defineComponent({
    name: 'Recommend',
  })
</script>

<script lang="ts" setup>
  import { ref, onMounted } from 'vue'
  import { reqVideoRecommend, videoRecommend } from '@/api/video'
  // const route = useRoute()
  const recommendVideo = ref<videoRecommend[]>([])
  async function getVideoRecommend(id: number | string) {
    const res = await reqVideoRecommend(id)
    if (res.length > 4) res.length = 4 //只要4个
    recommendVideo.value = res
  }

  const props = defineProps<{
    aid: number
    bvid: string
  }>()

  onMounted(() => {
    getVideoRecommend(props.aid || props.bvid)
  })

  const route = useRoute()
  watch(
    () => route.query,
    (query) => {
      if (!route.fullPath.includes('video')) return
      if (Number(query.aid) !== props.aid || query.bvid !== props.bvid) location.reload()
    },
  )
</script>

<style lang="less" scoped>
  .recommend {
    height: 390px;
    overflow: hidden;
    .recommend-top {
      width: 320px;
      height: 24px;
      font-size: 16px;
      margin-bottom: 6px;
    }
    .recommend-list {
      display: flex;
      padding: 6px 0;
      cursor: pointer;
      .recommend-video {
        width: 141px;
        height: 80px;
        .video {
          width: 141px;
          height: 80px;
        }
      }
      .recommend-info {
        margin-left: 10px;
        .recommend-title {
          color: #222;
          font-size: 14px;
          overflow: hidden;
          text-overflow: ellipsis;
          /*这两个属性就可以开启行末省略，文字超出后在末尾会变成省略号三个点 ... 但这样只能用于单行文本！ */

          /* 多行文本省略，需要加上下面的属性 */
          display: -webkit-box; /* 开启-webkit-box */
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .recommend-up {
          color: #999;
          font-size: 12px;
          margin-top: 6px;
          margin-bottom: 4px;
        }
        .recommend-number {
          color: #999;
          font-size: 12px;
        }
      }
    }
  }
</style>
